/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package presenter;

import java.util.ArrayList;

/**
 *
 * @author Al
 */
public class BibleBook {
    
    private String bookName;
    private ArrayList<ArrayList<SongVerse>> verses;
    private int chapter,verse;
    
    public BibleBook(String bookName) {
        this.bookName=bookName;
        verses=new ArrayList<ArrayList<SongVerse>>();
    }
    
    public void addVerse(int chapter,int verse,String[] text) {
        if(chapter>this.chapter) {
           //System.out.println(bookName+" adding new chapter "+chapter);
            
            verses.add(new ArrayList<SongVerse>());
        }
        for(int i=0; i<text.length; i++){
               //System.out.println(text[i]);
        }
        SongVerse sv=new SongVerse();
        sv.setText(text);
        sv.setType(bookName+" "+chapter+":"+verse);
        sv.bibleVerse=true;
       //System.out.println("");
        //System.out.println(chapter+" "+verse);
        verses.get(chapter-1).add(sv);
        this.chapter=chapter;
        this.verse=verse;
    }
    
    public SongVerse[] getVerses(int chapterStart, int verseStart, int chapterEnd, int verseEnd) {
        //adjust for indexing
        
        
        ArrayList<SongVerse> result=new ArrayList<SongVerse>();
        ArrayList<SongVerse> chapter=verses.get(chapterStart);
        //System.out.println(verseEnd);
        if(chapterStart==chapterEnd){
            for(int i=verseStart; i<=verseEnd; i++) {
                result.add(chapter.get(i));
            }
            return result.toArray(new SongVerse[verseEnd+1]);
        }
        
        for(int i=verseStart; i<chapter.size(); i++) {
            result.add(chapter.get(i));
        }
        for(int i=chapterStart+1; i<chapterEnd; i++){
            chapter=verses.get(i);
            for(int j=0; j<chapter.size(); j++) {
                result.add(chapter.get(j));
            }
        }
        chapter=verses.get(chapterEnd);
        for(int i=0; i<=verseEnd; i++) {
                result.add(chapter.get(i));
        }
        return result.toArray(new SongVerse[1]);
    }
    
    public int getNumberOfChapters() {
        return verses.size();
    }
    
    public int getNumberOfVerses(int chapter) {
        return verses.get(chapter).size();
    }
    
    public String getName() {
        return bookName;
    }
}
